package work.shyk.kongMonitor.dto.param;

import com.fasterxml.jackson.databind.JsonNode;
import work.shyk.kongMonitor.dto.param.interfaces.QueryObj;
import work.shyk.kongMonitor.dto.param.interfaces.Parser;
import work.shyk.kongMonitor.dto.result.interfaces.ValueReceiver;

import java.util.HashMap;
import java.util.function.Supplier;

/**
 * description: <br>
 * createTime: 2021/3/24 16:52 <br>
 *
 * @author zzh
 */
public abstract class AbstractAggsQuery<T> extends HashMap {
    protected Parser<T> parser;

    protected String key;

    public AbstractAggsQuery(String key) {
        this.key = key;
    }

    public AbstractAggsQuery(String key, AggsEnums aggsEnums, QueryObj obj) {
        this(key);
        put(aggsEnums.getValue(), obj);
    }

    public AbstractAggsQuery(String key, AggsEnums aggsEnums, QueryObj obj, Parser paser) {
        this(key);
        put(aggsEnums.getValue(), obj);
        setParser(paser);
    }


    public  abstract T parse(JsonNode jsonNode, Supplier<ValueReceiver> receiverSupplier);

    public AbstractAggsQuery setParser(Parser<T> parser) {
        this.parser = parser;
        return this;
    }


    public String getKey() {
        return key;
    }
}
